﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="UserTypeList.aspx.cs" Inherits="Atomic.Web.Pages.UserTypeList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" language="javascript">
        $(function () {
            var typeID = 0;
            //初始化编辑窗口
            $('#userTypeEditorForm').dialog({
                title: '新建/编辑用户类型',
                closed: true,
                top: $(window).height() * 0.25,
                buttons: [
                    {
                        text: '确定',
                        handler: function () {
                            //保存类型信息
                            $.post('/Handlers/User/UserHandler.ashx/?method=AddOrUpdateUserType',
                            {
                                id: typeID,
                                name: $('#txtUserTypeName').val()
                            },
                            function (data) {
                                if (data.Success) {
                                    typeID = 0;
                                    $('#txtUserTypeName').val('');
                                    $('#userTypeList').datagrid('load');
                                    $('#userTypeEditorForm').dialog('close');
                                } else {
                                    $.messager.alert("提示信息", data.Message, 'warning');
                                }
                            },
                            'json');
                        }
                    },
                    {
                        text: '取消',
                        handler: function () {
                            $('#userTypeEditorForm').dialog('close');
                        }
                    }
                ]
                });

                //初始化扩展属性管理弹出窗口
                $('<div id="userTypePropertyListWindow"></div>').appendTo('body').window({
                    href: 'javascript:void(0);',
                    title: '扩展属性管理',
                    closed: true,
                    maximized: true //初始最大化
                });

            //加载用户类型列表
            $('#userTypeList').datagrid({
                url: '/Handlers/User/UserHandler.ashx/?method=GetUserTypes',
                method: 'post',
                fitColumns: true,
                singleSelect: true,
                columns: [[
            		{ field: "Name", title: '名称', width: 250 },
            		{ field: "Opts", title: '操作', width: 80,
            		    formatter: function (v, d) {
            		        //按记录索引生成修改标签
            		        var a1 = '<a class="UpdateUserType" value="' + d.ID + '" href="javascript:void(0);">修改</a> ';
            		        var a2 = '<a class="RemoveUserType" value="' + d.ID + '" href="javascript:void(0);">删除</a> ';
            		        var a3 = '<a class="UserTypePropertyMgr" value="' + d.ID + '" href="javascript:void(0);">扩展属性</a>';
            		        return a1 + a2 + a3;
            		    }
            		}
            	]],
                onLoadSuccess: function () {
                    //修改标签点击，加载预修改记录
                    $('.UpdateUserType').click(function () {
                        var id = $(this).attr('value'); //预修改记录的ID
                        $.each($('#userTypeList').datagrid('getRows'), function (i, d) {
                            if (d.ID == id) {
                                typeID = id;
                                $('#txtUserTypeName').val(d.Name);
                                $('#userTypeEditorForm').dialog('open');
                                return false;   //jq退出循环
                            }
                        });
                    });
                    //删除确认
                    $('.RemoveUserType').click(function () {
                        var id = $(this).attr('value'); //预删除记录的ID
                        $.messager.confirm('提示信息', '确定删除此用户类型？', function (btn) {
                            if (btn) {
                                $.post('/Handlers/User/UserHandler.ashx/?method=RemoveUserType',
                                {
                                    ID: id
                                },
                                function (data) {
                                    if (data.Success) {
                                        $('#userTypeList').datagrid('reload');
                                    } else {
                                        $.messager.alert('提示信息', data.Message, 'warning');
                                    }
                                },
                                'json');
                            }
                        });
                    });
                    //修改标签点击，加载预修改记录
                    $('.UserTypePropertyMgr').click(function () {
                        var id = $(this).attr('value'); 
                        $('#userTypePropertyListWindow').window('open');
                        $('#userTypePropertyListWindow').window('refresh', '../UserTypeFields.aspx?TypeID=' + id);
                    });
                },
                toolbar: [
                    {
                        text: '新建用户类型',
                        iconCls: 'icon-add',
                        handler: function () {
                            typeID = 0;
                            $('#txtUserTypeName').val('');
                            $('#userTypeEditorForm').dialog('open');
                        }
                    }
                ]
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="userTypeList">
    </div>
    <div id="userTypeEditorForm">
        <table>
            <tr>
                <td>
                    用户类型
                </td>
                <td>
                    <input type="text" id="txtUserTypeName" value="" />
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
